home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / ws_ping.zip / WSPI_SRC.ZIP / WINSOCK.H < prev    next >
C/C++ Source or Header  |  1993-09-07  |  29KB  |  827 lines

  1. /* WINSOCK.H--definitions to be used with the WINSOCK.DLL
  2.  *
  3.  * This header file corresponds to version 1.1 of the Windows Sockets specification.
  4.  *
  5.  * This file includes parts which are Copyright (c) 1982-1986 Regents
  6.  * of the University of California.  All rights reserved.  The
  7.  * Berkeley Software License Agreement specifies the terms and
  8.  * conditions for redistribution.
  9.  */
  10.  
  11. #ifndef _WINSOCKAPI_
  12. #define _WINSOCKAPI_
  13.  
  14. /*
  15.  * Pull in WINDOWS.H if necessary
  16.  */
  17. #ifndef _INC_WINDOWS
  18. #include <windows.h>
  19. #endif /* _INC_WINDOWS */
  20.  
  21. /*
  22.  * Basic system type definitions, taken from the BSD file sys/types.h.
  23.  */
  24. typedef unsigned char   u_char;
  25. typedef unsigned short  u_short;
  26. typedef unsigned int    u_int;
  27. typedef unsigned long   u_long;
  28.  
  29. /*
  30.  * The new type to be used in all
  31.  * instances which refer to sockets.
  32.  */
  33. typedef u_int           SOCKET;
  34.  
  35. /*
  36.  * Select uses arrays of SOCKETs.  These macros manipulate such
  37.  * arrays.  FD_SETSIZE may be defined by the user before including
  38.  * this file, but the default here should be >= 64.
  39.  *
  40.  * CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
  41.  * INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE.
  42.  */
  43. #ifndef FD_SETSIZE
  44. #define FD_SETSIZE      64
  45. #endif /* FD_SETSIZE */
  46.  
  47. typedef struct fd_set {
  48.         u_short fd_count;               /* how many are SET? */
  49.         SOCKET  fd_array[FD_SETSIZE];   /* an array of SOCKETs */
  50. } fd_set;
  51.  
  52. extern int PASCAL FAR __WSAFDIsSet(SOCKET, fd_set FAR *);
  53.  
  54. #define FD_CLR(fd, set) do { \
  55.     u_int __i; \
  56.     for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ; __i++) { \
  57.         if (((fd_set FAR *)(set))->fd_array[__i] == fd) { \
  58.             while (__i < ((fd_set FAR *)(set))->fd_count-1) { \
  59.                 ((fd_set FAR *)(set))->fd_array[__i] = \
  60.                     ((fd_set FAR *)(set))->fd_array[__i+1]; \
  61.                 __i++; \
  62.             } \
  63.             ((fd_set FAR *)(set))->fd_count--; \
  64.             break; \
  65.         } \
  66.     } \
  67. } while(0)
  68.  
  69. #define FD_SET(fd, set) do { \
  70.     if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) \
  71.         ((fd_set FAR *)(set))->fd_array[((fd_set FAR *)(set))->fd_count++]=fd;\
  72. } while(0)
  73.  
  74. #define FD_ZERO(set) (((fd_set FAR *)(set))->fd_count=0)
  75.  
  76. #define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)fd, (fd_set FAR *)set)
  77.  
  78. /*
  79.  * Structure used in select() call, taken from the BSD file sys/time.h.
  80.  */
  81. struct timeval {
  82.         long    tv_sec;         /* seconds */
  83.         long    tv_usec;        /* and microseconds */
  84. };
  85.  
  86. /*
  87.  * Operations on timevals.
  88.  *
  89.  * NB: timercmp does not work for >= or <=.
  90.  */
  91. #define timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec)
  92. #define timercmp(tvp, uvp, cmp) \
  93.         ((tvp)->tv_sec cmp (uvp)->tv_sec || \
  94.          (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
  95. #define timerclear(tvp)         (tvp)->tv_sec = (tvp)->tv_usec = 0
  96.  
  97. /*
  98.  * Commands for ioctlsocket(),  taken from the BSD file fcntl.h.
  99.  *
  100.  *
  101.  * Ioctl's have the command encoded in the lower word,
  102.  * and the size of any in or out parameters in the upper
  103.  * word.  The high 2 bits of the upper word are used
  104.  * to encode the in/out status of the parameter; for now
  105.  * we restrict parameters to at most 128 bytes.
  106.  */
  107. #define IOCPARM_MASK    0x7f            /* parameters must be < 128 bytes */
  108. #define IOC_VOID        0x20000000      /* no parameters */
  109. #define IOC_OUT         0x40000000      /* copy out parameters */
  110. #define IOC_IN          0x80000000      /* copy in parameters */
  111. #define IOC_INOUT       (IOC_IN|IOC_OUT)
  112.                                         /* 0x20000000 distinguishes new &
  113.                                            old ioctl's */
  114. #define _IO(x,y)        (IOC_VOID|(x<<8)|y)
  115.  
  116. #define _IOR(x,y,t)     (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
  117.  
  118. #define _IOW(x,y,t)     (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
  119.  
  120. #define FIONREAD    _IOR('f', 127, u_long) /* get # bytes to read */
  121. #define FIONBIO     _IOW('f', 126, u_long) /* set/clear non-blocking i/o */
  122. #define FIOASYNC    _IOW('f', 125, u_long) /* set/clear async i/o */
  123.  
  124. /* Socket I/O Controls */
  125. #define SIOCSHIWAT  _IOW('s',  0, u_long)  /* set high watermark */
  126. #define SIOCGHIWAT  _IOR('s',  1, u_long)  /* get high watermark */
  127. #define SIOCSLOWAT  _IOW('s',  2, u_long)  /* set low watermark */
  128. #define SIOCGLOWAT  _IOR('s',  3, u_long)  /* get low watermark */
  129. #define SIOCATMARK  _IOR('s',  7, u_long)  /* at oob mark? */
  130.  
  131. /*
  132.  * Structures returned by network data base library, taken from the
  133.  * BSD file netdb.h.  All addresses are supplied in host order, and
  134.  * returned in network order (suitable for use in system calls).
  135.  */
  136.  
  137. struct  hostent {
  138.         char    FAR * h_name;           /* official name of host */
  139.         char    FAR * FAR * h_aliases;  /* alias list */
  140.         short   h_addrtype;             /* host address type */
  141.         short   h_length;               /* length of address */
  142.         char    FAR * FAR * h_addr_list; /* list of addresses */
  143. #define h_addr  h_addr_list[0]          /* address, for backward compat */
  144. };
  145.  
  146. /*
  147.  * It is assumed here that a network number
  148.  * fits in 32 bits.
  149.  */
  150. struct  netent {
  151.         char    FAR * n_name;           /* official name of net */
  152.         char    FAR * FAR * n_aliases;  /* alias list */
  153.         short   n_addrtype;             /* net address type */
  154.         u_long  n_net;                  /* network # */
  155. };
  156.  
  157. struct  servent {
  158.         char    FAR * s_name;           /* official service name */
  159.         char    FAR * FAR * s_aliases;  /* alias list */
  160.         short   s_port;                 /* port # */
  161.         char    FAR * s_proto;          /* protocol to use */
  162. };
  163.  
  164. struct  protoent {
  165.         char    FAR * p_name;           /* official protocol name */
  166.         char    FAR * FAR * p_aliases;  /* alias list */
  167.         short   p_proto;                /* protocol # */
  168. };
  169.  
  170. /*
  171.  * Constants and structures defined by the internet system,
  172.  * Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
  173.  */
  174.  
  175. /*
  176.  * Protocols
  177.  */
  178. #define IPPROTO_IP              0               /* dummy for IP */
  179. #define IPPROTO_ICMP            1               /* control message protocol */
  180. #define IPPROTO_GGP             2               /* gateway^2 (deprecated) */
  181. #define IPPROTO_TCP             6               /* tcp */
  182. #define IPPROTO_PUP             12              /* pup */
  183. #define IPPROTO_UDP             17              /* user datagram protocol */
  184. #define IPPROTO_IDP             22              /* xns idp */
  185. #define IPPROTO_ND              77              /* UNOFFICIAL net disk proto */
  186.  
  187. #define IPPROTO_RAW             255             /* raw IP packet */
  188. #define IPPROTO_MAX             256
  189.  
  190. /*
  191.  * Port/socket numbers: network standard functions
  192.  */
  193. #define IPPORT_ECHO             7
  194. #define IPPORT_DISCARD          9
  195. #define IPPORT_SYSTAT           11
  196. #define IPPORT_DAYTIME          13
  197. #define IPPORT_NETSTAT          15
  198. #define IPPORT_FTP              21
  199. #define IPPORT_TELNET           23
  200. #define IPPORT_SMTP             25
  201. #define IPPORT_TIMESERVER       37
  202. #define IPPORT_NAMESERVER       42
  203. #define IPPORT_WHOIS            43
  204. #define IPPORT_MTP              57
  205.  
  206. /*
  207.  * Port/socket numbers: host specific functions
  208.  */
  209. #define IPPORT_TFTP             69
  210. #define IPPORT_RJE              77
  211. #define IPPORT_FINGER           79
  212. #define IPPORT_TTYLINK          87
  213. #define IPPORT_SUPDUP           95
  214.  
  215. /*
  216.  * UNIX TCP sockets
  217.  */
  218. #define IPPORT_EXECSERVER       512
  219. #define IPPORT_LOGINSERVER      513
  220. #define IPPORT_CMDSERVER        514
  221. #define IPPORT_EFSSERVER        520
  222.  
  223. /*
  224.  * UNIX UDP sockets
  225.  */
  226. #define IPPORT_BIFFUDP          512
  227. #define IPPORT_WHOSERVER        513
  228. #define IPPORT_ROUTESERVER      520
  229.                                         /* 520+1 also used */
  230.  
  231. /*
  232.  * Ports < IPPORT_RESERVED are reserved for
  233.  * privileged processes (e.g. root).
  234.  */
  235. #define IPPORT_RESERVED         1024
  236.  
  237. /*
  238.  * Link numbers
  239.  */
  240. #define IMPLINK_IP              155
  241. #define IMPLINK_LOWEXPER        156
  242. #define IMPLINK_HIGHEXPER       158
  243.  
  244. /*
  245.  * Internet address (old style... should be updated)
  246.  */
  247. struct in_addr {
  248.         union {
  249.                 struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
  250.                 struct { u_short s_w1,s_w2; } S_un_w;
  251.                 u_long S_addr;
  252.         } S_un;
  253. #define s_addr  S_un.S_addr
  254.                                 /* can be used for most tcp & ip code */
  255. #define s_host  S_un.S_un_b.s_b2
  256.                                 /* host on imp */
  257. #define s_net   S_un.S_un_b.s_b1
  258.                                 /* network */
  259. #define s_imp   S_un.S_un_w.s_w2
  260.                                 /* imp */
  261. #define s_impno S_un.S_un_b.s_b4
  262.                                 /* imp # */
  263. #define s_lh    S_un.S_un_b.s_b3
  264.                                 /* logical host */
  265. };
  266.  
  267. /*
  268.  * Definitions of bits in internet address integers.
  269.  * On subnets, the decomposition of addresses to host and net parts
  270.  * is done according to subnet mask, not the masks here.
  271.  */
  272. #define IN_CLASSA(i)            (((long)(i) & 0x80000000) == 0)
  273. #define IN_CLASSA_NET           0xff000000
  274. #define IN_CLASSA_NSHIFT        24
  275. #define IN_CLASSA_HOST          0x00ffffff
  276. #define IN_CLASSA_MAX           128
  277.  
  278. #define IN_CLASSB(i)            (((long)(i) & 0xc0000000) == 0x80000000)
  279. #define IN_CLASSB_NET           0xffff0000
  280. #define IN_CLASSB_NSHIFT        16
  281. #define IN_CLASSB_HOST          0x0000ffff
  282. #define IN_CLASSB_MAX           65536
  283.  
  284. #define IN_CLASSC(i)            (((long)(i) & 0xc0000000) == 0xc0000000)
  285. #define IN_CLASSC_NET           0xffffff00
  286. #define IN_CLASSC_NSHIFT        8
  287. #define IN_CLASSC_HOST          0x000000ff
  288.  
  289. #define INADDR_ANY              (u_long)0x00000000
  290. #define INADDR_LOOPBACK         0x7f000001
  291. #define INADDR_BROADCAST        (u_long)0xffffffff    
  292. #define INADDR_NONE             0xffffffff
  293.  
  294. /*
  295.  * Socket address, internet style.
  296.  */
  297. struct sockaddr_in {
  298.         short   sin_family;
  299.         u_short sin_port;
  300.         struct  in_addr sin_addr;
  301.         char    sin_zero[8];
  302. };
  303.  
  304. #define WSADESCRIPTION_LEN      256
  305. #define WSASYS_STATUS_LEN       128
  306.  
  307. typedef struct WSAData {
  308.         WORD                    wVersion;
  309.         WORD                    wHighVersion;
  310.         char                    szDescription[WSADESCRIPTION_LEN+1];
  311.         char                    szSystemStatus[WSASYS_STATUS_LEN+1];
  312.         unsigned short          iMaxSockets;
  313.         unsigned short          iMaxUdpDg;
  314.         char FAR *              lpVendorInfo;
  315. } WSADATA;
  316.  
  317. typedef WSADATA FAR *LPWSADATA;
  318.  
  319. /*
  320.  * Options for use with [gs]etsockopt at the IP level.
  321.  */
  322. #define IP_OPTIONS      1               /* set/get IP per-packet options */
  323.  
  324. /*
  325.  * Definitions related to sockets: types, address families, options,
  326.  * taken from the BSD file sys/socket.h.
  327.  */
  328.  
  329. /*
  330.  * This is used instead of -1, since the
  331.  * SOCKET type is unsigned.
  332.  */
  333. #define INVALID_SOCKET  (SOCKET)(~0)
  334. #define SOCKET_ERROR            (-1)
  335.  
  336. /*
  337.  * Types
  338.  */
  339. #define SOCK_STREAM     1               /* stream socket */
  340. #define SOCK_DGRAM      2               /* datagram socket */
  341. #define SOCK_RAW        3               /* raw-protocol interface */
  342. #define SOCK_RDM        4               /* reliably-delivered message */
  343. #define SOCK_SEQPACKET  5               /* sequenced packet stream */
  344.  
  345. /*
  346.  * Option flags per-socket.
  347.  */
  348. #define SO_DEBUG        0x0001          /* turn on debugging info recording */
  349. #define SO_ACCEPTCONN   0x0002          /* socket has had listen() */
  350. #define SO_REUSEADDR    0x0004          /* allow local address reuse */
  351. #define SO_KEEPALIVE    0x0008          /* keep connections alive */
  352. #define SO_DONTROUTE    0x0010          /* just use interface addresses */
  353. #define SO_BROADCAST    0x0020          /* permit sending of broadcast msgs */
  354. #define SO_USELOOPBACK  0x0040          /* bypass hardware when possible */
  355. #define SO_LINGER       0x0080          /* linger on close if data present */
  356. #define SO_OOBINLINE    0x0100          /* leave received OOB data in line */
  357.  
  358. #define SO_DONTLINGER   (u_int)(~SO_LINGER)
  359.  
  360. /*
  361.  * Additional options.
  362.  */
  363. #define SO_SNDBUF       0x1001          /* send buffer size */
  364. #define SO_RCVBUF       0x1002          /* receive buffer size */
  365. #define SO_SNDLOWAT     0x1003          /* send low-water mark */
  366. #define SO_RCVLOWAT     0x1004          /* receive low-water mark */
  367. #define SO_SNDTIMEO     0x1005          /* send timeout */
  368. #define SO_RCVTIMEO     0x1006          /* receive timeout */
  369. #define SO_ERROR        0x1007          /* get error status and clear */
  370. #define SO_TYPE         0x1008          /* get socket type */
  371.  
  372. /*
  373.  * TCP options.
  374.  */
  375. #define TCP_NODELAY     0x0001
  376.  
  377. /*
  378.  * Address families.
  379.  */
  380. #define AF_UNSPEC       0               /* unspecified */
  381. #define AF_UNIX         1               /* local to host (pipes, portals) */
  382. #define AF_INET         2               /* internetwork: UDP, TCP, etc. */
  383. #define AF_IMPLINK      3               /* arpanet imp addresses */
  384. #define AF_PUP          4               /* pup protocols: e.g. BSP */
  385. #define AF_CHAOS        5               /* mit CHAOS protocols */
  386. #define AF_NS           6               /* XEROX NS protocols */
  387. #define AF_ISO          7               /* ISO protocols */
  388. #define AF_OSI          AF_ISO          /* OSI is ISO */
  389. #define AF_ECMA         8               /* european computer manufacturers */
  390. #define AF_DATAKIT      9               /* datakit protocols */
  391. #define AF_CCITT        10              /* CCITT protocols, X.25 etc */
  392. #define AF_SNA          11              /* IBM SNA */
  393. #define AF_DECnet       12              /* DECnet */
  394. #define AF_DLI          13              /* Direct data link interface */
  395. #define AF_LAT          14              /* LAT */
  396. #define AF_HYLINK       15              /* NSC Hyperchannel */
  397. #define AF_APPLETALK    16              /* AppleTalk */
  398. #define AF_NETBIOS      17              /* NetBios-style addresses */
  399.  
  400. #define AF_MAX          18
  401.  
  402. /*
  403.  * Structure used by kernel to store most
  404.  * addresses.
  405.  */
  406. struct sockaddr {
  407.         u_short sa_family;              /* address family */
  408.         char    sa_data[14];            /* up to 14 bytes of direct address */
  409. };
  410.  
  411. /*
  412.  * Structure used by kernel to pass protocol
  413.  * information in raw sockets.
  414.  */
  415. struct sockproto {
  416.         u_short sp_family;              /* address family */
  417.         u_short sp_protocol;            /* protocol */
  418. };
  419.  
  420. /*
  421.  * Protocol families, same as address families for now.
  422.  */
  423. #define PF_UNSPEC       AF_UNSPEC
  424. #define PF_UNIX         AF_UNIX
  425. #define PF_INET         AF_INET
  426. #define PF_IMPLINK      AF_IMPLINK
  427. #define PF_PUP          AF_PUP
  428. #define PF_CHAOS        AF_CHAOS
  429. #define PF_NS           AF_NS
  430. #define PF_ISO          AF_ISO
  431. #define PF_OSI          AF_OSI
  432. #define PF_ECMA         AF_ECMA
  433. #define PF_DATAKIT      AF_DATAKIT
  434. #define PF_CCITT        AF_CCITT
  435. #define PF_SNA          AF_SNA
  436. #define PF_DECnet       AF_DECnet
  437. #define PF_DLI          AF_DLI
  438. #define PF_LAT          AF_LAT
  439. #define PF_HYLINK       AF_HYLINK
  440. #define PF_APPLETALK    AF_APPLETALK
  441.  
  442. #define PF_MAX          AF_MAX
  443.  
  444. /*
  445.  * Structure used for manipulating linger option.
  446.  */
  447. struct  linger {
  448.         u_short l_onoff;                /* option on/off */
  449.         u_short l_linger;               /* linger time */
  450. };
  451.  
  452. /*
  453.  * Level number for (get/set)sockopt() to apply to socket itself.
  454.  */
  455. #define SOL_SOCKET      0xffff          /* options for socket level */
  456.  
  457. /*
  458.  * Maximum queue length specifiable by listen.
  459.  */
  460. #define SOMAXCONN       5
  461.  
  462. #define MSG_OOB         0x1             /* process out-of-band data */
  463. #define MSG_PEEK        0x2             /* peek at incoming message */
  464. #define MSG_DONTROUTE   0x4             /* send without using routing tables */
  465.  
  466. #define MSG_MAXIOVLEN   16
  467.  
  468. /*
  469.  * Define constant based on rfc883, used by gethostbyxxxx() calls.
  470.  */
  471. #define MAXGETHOSTSTRUCT        1024
  472.  
  473. /*
  474.  * Define flags to be used with the WSAAsyncSelect() call.
  475.  */
  476. #define FD_READ         0x01
  477. #define FD_WRITE        0x02
  478. #define FD_OOB          0x04
  479. #define FD_ACCEPT       0x08
  480. #define FD_CONNECT      0x10
  481. #define FD_CLOSE        0x20
  482.  
  483. /*
  484.  * All Windows Sockets error constants are biased by WSABASEERR from
  485.  * the "normal"
  486.  */
  487. #define WSABASEERR              10000
  488. /*
  489.  * Windows Sockets definitions of regular Microsoft C error constants
  490.  */
  491. #define WSAEINTR                (WSABASEERR+4)
  492. #define WSAEBADF                (WSABASEERR+9)
  493. #define WSAEACCES               (WSABASEERR+13)
  494. #define WSAEFAULT               (WSABASEERR+14)
  495. #define WSAEINVAL               (WSABASEERR+22)
  496. #define WSAEMFILE               (WSABASEERR+24)
  497.  
  498. /*
  499.  * Windows Sockets definitions of regular Berkeley error constants
  500.  */
  501. #define WSAEWOULDBLOCK          (WSABASEERR+35)
  502. #define WSAEINPROGRESS          (WSABASEERR+36)
  503. #define WSAEALREADY             (WSABASEERR+37)
  504. #define WSAENOTSOCK             (WSABASEERR+38)
  505. #define WSAEDESTADDRREQ         (WSABASEERR+39)
  506. #define WSAEMSGSIZE             (WSABASEERR+40)
  507. #define WSAEPROTOTYPE           (WSABASEERR+41)
  508. #define WSAENOPROTOOPT          (WSABASEERR+42)
  509. #define WSAEPROTONOSUPPORT      (WSABASEERR+43)
  510. #define WSAESOCKTNOSUPPORT      (WSABASEERR+44)
  511. #define WSAEOPNOTSUPP           (WSABASEERR+45)
  512. #define WSAEPFNOSUPPORT         (WSABASEERR+46)
  513. #define WSAEAFNOSUPPORT         (WSABASEERR+47)
  514. #define WSAEADDRINUSE           (WSABASEERR+48)
  515. #define WSAEADDRNOTAVAIL        (WSABASEERR+49)
  516. #define WSAENETDOWN             (WSABASEERR+50)
  517. #define WSAENETUNREACH          (WSABASEERR+51)
  518. #define WSAENETRESET            (WSABASEERR+52)
  519. #define WSAECONNABORTED         (WSABASEERR+53)
  520. #define WSAECONNRESET           (WSABASEERR+54)
  521. #define WSAENOBUFS              (WSABASEERR+55)
  522. #define WSAEISCONN              (WSABASEERR+56)
  523. #define WSAENOTCONN             (WSABASEERR+57)
  524. #define WSAESHUTDOWN            (WSABASEERR+58)
  525. #define WSAETOOMANYREFS         (WSABASEERR+59)
  526. #define WSAETIMEDOUT            (WSABASEERR+60)
  527. #define WSAECONNREFUSED         (WSABASEERR+61)
  528. #define WSAELOOP                (WSABASEERR+62)
  529. #define WSAENAMETOOLONG         (WSABASEERR+63)
  530. #define WSAEHOSTDOWN            (WSABASEERR+64)
  531. #define WSAEHOSTUNREACH         (WSABASEERR+65)
  532. #define WSAENOTEMPTY            (WSABASEERR+66)
  533. #define WSAEPROCLIM             (WSABASEERR+67)
  534. #define WSAEUSERS               (WSABASEERR+68)
  535. #define WSAEDQUOT               (WSABASEERR+69)
  536. #define WSAESTALE               (WSABASEERR+70)
  537. #define WSAEREMOTE              (WSABASEERR+71)
  538.  
  539. /*
  540.  * Extended Windows Sockets error constant definitions
  541.  */
  542. #define WSASYSNOTREADY          (WSABASEERR+91)
  543. #define WSAVERNOTSUPPORTED      (WSABASEERR+92)
  544. #define WSANOTINITIALISED       (WSABASEERR+93)
  545.  
  546. /*
  547.  * Error return codes from gethostbyname() and gethostbyaddr()
  548.  * (when using the resolver). Note that these errors are
  549.  * retrieved via WSAGetLastError() and must therefore follow
  550.  * the rules for avoiding clashes with error numbers from
  551.  * specific implementations or language run-time systems.
  552.  * For this reason the codes are based at WSABASEERR+1001.
  553.  * Note also that [WSA]NO_ADDRESS is defined only for
  554.  * compatibility purposes.
  555.  */
  556.  
  557. #define h_errno         WSAGetLastError()
  558.  
  559. /* Authoritative Answer: Host not found */
  560. #define WSAHOST_NOT_FOUND       (WSABASEERR+1001)
  561. #define HOST_NOT_FOUND          WSAHOST_NOT_FOUND
  562.  
  563. /* Non-Authoritative: Host not found, or SERVERFAIL */
  564. #define WSATRY_AGAIN            (WSABASEERR+1002)
  565. #define TRY_AGAIN               WSATRY_AGAIN
  566.  
  567. /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
  568. #define WSANO_RECOVERY          (WSABASEERR+1003)
  569. #define NO_RECOVERY             WSANO_RECOVERY
  570.  
  571. /* Valid name, no data record of requested type */
  572. #define WSANO_DATA              (WSABASEERR+1004)
  573. #define NO_DATA                 WSANO_DATA
  574.  
  575. /* no address, look for MX record */
  576. #define WSANO_ADDRESS           WSANO_DATA
  577. #define NO_ADDRESS              WSANO_ADDRESS
  578.  
  579. /*
  580.  * Windows Sockets errors redefined as regular Berkeley error constants
  581.  */
  582. #define EWOULDBLOCK             WSAEWOULDBLOCK
  583. #define EINPROGRESS             WSAEINPROGRESS
  584. #define EALREADY                WSAEALREADY
  585. #define ENOTSOCK                WSAENOTSOCK
  586. #define EDESTADDRREQ            WSAEDESTADDRREQ
  587. #define EMSGSIZE                WSAEMSGSIZE
  588. #define EPROTOTYPE              WSAEPROTOTYPE
  589. #define ENOPROTOOPT             WSAENOPROTOOPT
  590. #define EPROTONOSUPPORT         WSAEPROTONOSUPPORT
  591. #define ESOCKTNOSUPPORT         WSAESOCKTNOSUPPORT
  592. #define EOPNOTSUPP              WSAEOPNOTSUPP
  593. #define EPFNOSUPPORT            WSAEPFNOSUPPORT
  594. #define EAFNOSUPPORT            WSAEAFNOSUPPORT
  595. #define EADDRINUSE              WSAEADDRINUSE
  596. #define EADDRNOTAVAIL           WSAEADDRNOTAVAIL
  597. #define ENETDOWN                WSAENETDOWN
  598. #define ENETUNREACH             WSAENETUNREACH
  599. #define ENETRESET               WSAENETRESET
  600. #define ECONNABORTED            WSAECONNABORTED
  601. #define ECONNRESET              WSAECONNRESET
  602. #define ENOBUFS                 WSAENOBUFS
  603. #define EISCONN                 WSAEISCONN
  604. #define ENOTCONN                WSAENOTCONN
  605. #define ESHUTDOWN               WSAESHUTDOWN
  606. #define ETOOMANYREFS            WSAETOOMANYREFS
  607. #define ETIMEDOUT               WSAETIMEDOUT
  608. #define ECONNREFUSED            WSAECONNREFUSED
  609. #define ELOOP                   WSAELOOP
  610. #define ENAMETOOLONG            WSAENAMETOOLONG
  611. #define EHOSTDOWN               WSAEHOSTDOWN
  612. #define EHOSTUNREACH            WSAEHOSTUNREACH
  613. #define ENOTEMPTY               WSAENOTEMPTY
  614. #define EPROCLIM                WSAEPROCLIM
  615. #define EUSERS                  WSAEUSERS
  616. #define EDQUOT                  WSAEDQUOT
  617. #define ESTALE                  WSAESTALE
  618. #define EREMOTE                 WSAEREMOTE
  619.  
  620. /* Socket function prototypes */
  621.  
  622. #ifdef __cplusplus
  623. extern "C" {
  624. #endif
  625.  
  626. SOCKET PASCAL FAR accept (SOCKET s, struct sockaddr FAR *addr,
  627.                           int FAR *addrlen);
  628.  
  629. int PASCAL FAR bind (SOCKET s, const struct sockaddr FAR *addr, int namelen);
  630.  
  631. int PASCAL FAR closesocket (SOCKET s);
  632.  
  633. int PASCAL FAR connect (SOCKET s, const struct sockaddr FAR *name, int namelen);
  634.  
  635. int PASCAL FAR ioctlsocket (SOCKET s, long cmd, u_long FAR *argp);
  636.  
  637. int PASCAL FAR getpeername (SOCKET s, struct sockaddr FAR *name,
  638.                             int FAR * namelen);
  639.  
  640. int PASCAL FAR getsockname (SOCKET s, struct sockaddr FAR *name,
  641.                             int FAR * namelen);
  642.  
  643. int PASCAL FAR getsockopt (SOCKET s, int level, int optname,
  644.                            char FAR * optval, int FAR *optlen);
  645.  
  646. u_long PASCAL FAR htonl (u_long hostlong);
  647.  
  648. u_short PASCAL FAR htons (u_short hostshort);
  649.  
  650. unsigned long PASCAL FAR inet_addr (const char FAR * cp);
  651.  
  652. char FAR * PASCAL FAR inet_ntoa (struct in_addr in);
  653.  
  654. int PASCAL FAR listen (SOCKET s, int backlog);
  655.  
  656. u_long PASCAL FAR ntohl (u_long netlong);
  657.  
  658. u_short PASCAL FAR ntohs (u_short netshort);
  659.  
  660. int PASCAL FAR recv (SOCKET s, char FAR * buf, int len, int flags);
  661.  
  662. int PASCAL FAR recvfrom (SOCKET s, char FAR * buf, int len, int flags,
  663.                          struct sockaddr FAR *from, int FAR * fromlen);
  664.  
  665. int PASCAL FAR select (int nfds, fd_set FAR *readfds, fd_set FAR *writefds,
  666.                        fd_set FAR *exceptfds, const struct timeval FAR *timeout);
  667.  
  668. int PASCAL FAR send (SOCKET s, const char FAR * buf, int len, int flags);
  669.  
  670. int PASCAL FAR sendto (SOCKET s, const char FAR * buf, int len, int flags,
  671.                        const struct sockaddr FAR *to, int tolen);
  672.  
  673. int PASCAL FAR setsockopt (SOCKET s, int level, int optname,
  674.                            const char FAR * optval, int optlen);
  675.  
  676. int PASCAL FAR shutdown (SOCKET s, int how);
  677.  
  678. SOCKET PASCAL FAR socket (int af, int type, int protocol);
  679.  
  680. /* Database function prototypes */
  681.  
  682. struct hostent FAR * PASCAL FAR gethostbyaddr(const char FAR * addr,
  683.                                               int len, int type);
  684.  
  685. struct hostent FAR * PASCAL FAR gethostbyname(const char FAR * name);
  686.  
  687. int PASCAL FAR gethostname (char FAR * name, int namelen);
  688.  
  689. struct servent FAR * PASCAL FAR getservbyport(int port, const char FAR * proto);
  690.  
  691. struct servent FAR * PASCAL FAR getservbyname(const char FAR * name,
  692.                                               const char FAR * proto);
  693.  
  694. struct protoent FAR * PASCAL FAR getprotobynumber(int proto);
  695.  
  696. struct protoent FAR * PASCAL FAR getprotobyname(const char FAR * name);
  697.  
  698. /* Microsoft Windows Extension function prototypes */
  699.  
  700. int PASCAL FAR WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData);
  701.  
  702. int PASCAL FAR WSACleanup(void);
  703.  
  704. void PASCAL FAR WSASetLastError(int iError);
  705.  
  706. int PASCAL FAR WSAGetLastError(void);
  707.  
  708. BOOL PASCAL FAR WSAIsBlocking(void);
  709.  
  710. int PASCAL FAR WSAUnhookBlockingHook(void);
  711.  
  712. FARPROC PASCAL FAR WSASetBlockingHook(FARPROC lpBlockFunc);
  713.  
  714. int PASCAL FAR WSACancelBlockingCall(void);
  715.  
  716. HANDLE PASCAL FAR WSAAsyncGetServByName(HWND hWnd, u_int wMsg,
  717.                                         const char FAR * name, 
  718.                                         const char FAR * proto,
  719.                                         char FAR * buf, int buflen);
  720.  
  721. HANDLE PASCAL FAR WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, int port,
  722.                                         const char FAR * proto, char FAR * buf,
  723.                                         int buflen);
  724.  
  725. HANDLE PASCAL FAR WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg,
  726.                                          const char FAR * name, char FAR * buf,
  727.                                          int buflen);
  728.  
  729. HANDLE PASCAL FAR WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg,
  730.                                            int number, char FAR * buf,
  731.                                            int buflen);
  732.  
  733. HANDLE PASCAL FAR WSAAsyncGetHostByName(HWND hWnd, u_int wMsg,
  734.                                         const char FAR * name, char FAR * buf,
  735.                                         int buflen);
  736.  
  737. HANDLE PASCAL FAR WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg,
  738.                                         const char FAR * addr, int len, int type,
  739.                                         const char FAR * buf, int buflen);
  740.  
  741. int PASCAL FAR WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
  742.  
  743. int PASCAL FAR WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg,
  744.                                long lEvent);
  745.  
  746. #ifdef __cplusplus
  747. }
  748. #endif
  749.  
  750. /* Microsoft Windows Extended data types */
  751. typedef struct sockaddr SOCKADDR;
  752. typedef struct sockaddr *PSOCKADDR;
  753. typedef struct sockaddr FAR *LPSOCKADDR;
  754.  
  755. typedef struct sockaddr_in SOCKADDR_IN;
  756. typedef struct sockaddr_in *PSOCKADDR_IN;
  757. typedef struct sockaddr_in FAR *LPSOCKADDR_IN;
  758.  
  759. typedef struct linger LINGER;
  760. typedef struct linger *PLINGER;
  761. typedef struct linger FAR *LPLINGER;
  762.  
  763. typedef struct in_addr IN_ADDR;
  764. typedef struct in_addr *PIN_ADDR;
  765. typedef struct in_addr FAR *LPIN_ADDR;
  766.  
  767. typedef struct fd_set FD_SET;
  768. typedef struct fd_set *PFD_SET;
  769. typedef struct fd_set FAR *LPFD_SET;
  770.  
  771. typedef struct hostent HOSTENT;
  772. typedef struct hostent *PHOSTENT;
  773. typedef struct hostent FAR *LPHOSTENT;
  774.  
  775. typedef struct servent SERVENT;
  776. typedef struct servent *PSERVENT;
  777. typedef struct servent FAR *LPSERVENT;
  778.  
  779. typedef struct protoent PROTOENT;
  780. typedef struct protoent *PPROTOENT;
  781. typedef struct protoent FAR *LPPROTOENT;
  782.  
  783. typedef struct timeval TIMEVAL;
  784. typedef struct timeval *PTIMEVAL;
  785. typedef struct timeval FAR *LPTIMEVAL;
  786.  
  787. /*
  788.  * Windows message parameter composition and decomposition
  789.  * macros.
  790.  *
  791.  * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
  792.  * when constructing the response to a WSAAsyncGetXByY() routine.
  793.  */
  794. #define WSAMAKEASYNCREPLY(buflen,error)     MAKELONG(buflen,error)
  795. /*
  796.  * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
  797.  * when constructing the response to WSAAsyncSelect().
  798.  */
  799. #define WSAMAKESELECTREPLY(event,error)     MAKELONG(event,error)
  800. /*
  801.  * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
  802.  * to extract the buffer length from the lParam in the response
  803.  * to a WSAGetXByY().
  804.  */
  805. #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
  806. /*
  807.  * WSAGETASYNCERROR is intended for use by the Windows Sockets application
  808.  * to extract the error code from the lParam in the response
  809.  * to a WSAGetXByY().
  810.  */
  811. #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
  812. /*
  813.  * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
  814.  * to extract the event code from the lParam in the response
  815.  * to a WSAAsyncSelect().
  816.  */
  817. #define WSAGETSELECTEVENT(lParam)           LOWORD(lParam)
  818. /*
  819.  * WSAGETSELECTERROR is intended for use by the Windows Sockets application
  820.  * to extract the error code from the lParam in the response
  821.  * to a WSAAsyncSelect().
  822.  */
  823. #define WSAGETSELECTERROR(lParam)           HIWORD(lParam)
  824.  
  825. #endif  /* _WINSOCKAPI_ */
  826.  
  827.